﻿#region Using References

using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Beaker.OpenCube.Nbt;

#endregion

namespace Beaker.OpenCube.NbtEditor.Converters
{
	public class TreeItemTemplateSelector
		: DataTemplateSelector
	{
		public DataTemplate KeyEnumerableValueTemplate { get; set; }
		public DataTemplate KeyValueTemplate { get; set; }
		public DataTemplate EnumerableValueTemplate { get; set; }
		public DataTemplate ValueTemplate { get; set; }

		public override DataTemplate SelectTemplate( object item, DependencyObject container )
		{
			if( item is KeyValuePair<string, object> )
			{
				var pair = (KeyValuePair<string, object>)item;

				if( pair.Value is NbtDictionary || ( !( pair.Value is string ) && pair.Value is IEnumerable ) )
					return KeyEnumerableValueTemplate;
				return KeyValueTemplate;
			}

			if( !( item is string ) && item is IEnumerable )
				return EnumerableValueTemplate;

			return ValueTemplate;
		}
	}
}